<?php 
include_once('connection/connection.php');
//session_start();
//ob_start();
include('header.php');
include('menu.php');
$num_src = $_SESSION['num_src_village'];
//$_SESSION['num_src']=$num_src_village;
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<title>UFW Form</title>
</head>
<body>
<?php
$loc_id = $_SESSION['loc_id'];
if(isset($_POST['submit']))
{
		$fclick = true;
		for($i=1; $i<=$num_src; $i++)
		{
			$src_village='src_village'.$i;
			$tw='tw_no'.$i;
			$ow='ow_no'.$i;
			$dcb='dcb_no'.$i;
			$dam='dam_no'.$i;
			$canal='canal_no'.$i;
			$other='other_no'.$i;
			$src_village=$_POST[$src_village];
			$tw=$_POST[$tw];
			$ow=$_POST[$ow];
			$dcb=$_POST[$dcb];
			$dam=$_POST[$dam];
			$canal=$_POST[$canal];
			$other=$_POST[$other];
			$total_pump[$i] = $tw + $ow + $dcb + $dam + $canal + $other;
			$arr_hab_count_pump[$src_village] = $total_pump[$i];
			
			$q1="INSERT INTO tbl_dtls_ufw_pump_num(loc_id, src_village, tw, ow, dcb, dam, canal, other) VALUES ('$loc_id', '$src_village', '$tw', '$ow', '$dcb', '$dam', '$canal', '$other')";	
			$result1=mysql_query($q1);
		}	
			if($result1)
			{
				//header('Location: questionnaire3_2.php');
				//echo "success 1";	
				$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error inserting pump_reserv table <br>";
			}
			$totalsum_pump = array_sum($total_pump);
			$_SESSION['totalsum_pump']=$totalsum_pump;
			$_SESSION['arrSource_pump'] = $arr_hab_count_pump;
		$q1="SELECT DISTINCT  habit_name, habit_code FROM tbl_dtls_ufw_habit WHERE status_a_na='Applicable' AND loc_id='$loc_id'";
		//echo $q1;
		$result2=mysql_query($q1);
		$rows_num = mysql_num_rows($result2);
		$_SESSION['rows_num']=$rows_num;
		for($i=1; $i<=$rows_num; $i++)
		{
			$hcode='habit_code'.$i;
			$hname='habit_name'.$i;
			$type_habit='type_habit'.$i;
			$glr='glr_no'.$i;
			$glsr='glsr_no'.$i;
			$cwr='cwr_no'.$i;
			$ohsr='ohsr_no'.$i;
			
			$hcode=$_POST[$hcode];
			$hname=$_POST[$hname];
			$type_habit=$_POST[$type_habit]; 
			$glr=$_POST[$glr]; 
			$glsr=$_POST[$glsr]; 
			$cwr=$_POST[$cwr]; 
			$ohsr=$_POST[$ohsr]; 
		 
			$total_reserv[$i] = $glr + $glsr + $cwr + $ohsr;
			$arr_hab_count_reserv[$hname] = $total_reserv[$i];
			
			$qr1="INSERT INTO tbl_dtls_ufw_num_pump_reserv(loc_id, habitation_code, habitation_name, type_habit, glr, glsr, cwr, ohsr) VALUES ('$loc_id', '$hcode', '$hname', '$type_habit', '$glr', '$glsr', '$cwr', '$ohsr')";
			$result3=mysql_query($qr1);
		}	
			if($result3)
			{
				//header('Location: questionnaire3_2.php');
				//echo "success 1";	
				$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error inserting pump_reserv table <br>";
			}
			$totalsum_reserv = array_sum($total_reserv);
			$_SESSION['totalsum_reserv']=$totalsum_reserv;
			$_SESSION['arrSource_reserv'] = $arr_hab_count_reserv;
			if($errorIns==0) 
			{
				header('Location: ufw_3.php');
			}
			else 
			{ 
				echo $errorIns;exit;
			}
}			
else
{
	$fclick = false;
	$flag=0;
}			
?>
<div align="center">
<form action="" method="post" enctype="multipart/form-data" name="ufw_2" id="ufw_2" onSubmit="return validate3()">
	<table border="0" width="800" id="table1" cellspacing="0" cellpadding="0">
		<tr>
			<td height="16">
			<p align="center">
			<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#000000">
			UFW</font></p></td>
		</tr>
		<tr>
			<td height="18">
			<p align="center">
			<font style="font-size: 8.5pt" face="Arial" color="#000000">Page 2</font></p></td>
		</tr>
		
		<tr>
			<td bgcolor="#C5D8EB" height="29"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Number of Pumps in Source Village</font></span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="798" id="table4" cellspacing="1" cellpadding="0" bgcolor="#FDF9EE">
				<tr>
					<td colspan="14"><span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="154" align="center" rowspan="2" bgcolor="#F7E6B7">
						<font style="font-size: 8.5pt; font-style:normal" face="Verdana" color="#990000">
						Name of Source Village</font>				  </td>
					<td height="27" colspan="6" align="center" bgcolor="#F7E6B7">
					<address>
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Type of Sources</font>
					</address>				  </td>
				</tr>
				<tr>
					<td width="78" height="20" align="center" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">TW(Nos.)</font></td>
					<td align="center" width="76" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">OW(Nos.)</font></td>
					<td align="center" width="68" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">DCB(Nos.)</font></td>
					<td align="center" width="69" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Dam(Nos.)</font></td>
					<td align="center" width="72" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Canal(Nos.)</font></td>
					<td align="center" width="186" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Other(Nos.)</font></td>
				</tr>
				<?php
				$q="SELECT village FROM tbl_dtls_ufw_src_village where loc_id='$loc_id'";
				$result=mysql_query($q);
				$i=1;
			    while(list($src_village)=mysql_fetch_array($result))
				{
				?>
				<tr>
					<td width="154" height="22" align="center">
						<input type="text" name="src_village<?php echo $i;?>" id="src_village<?php echo $i;?>" value="<?php echo $src_village;?>" size="20" class="txt4" readonly />
				  <!--<input type="hidden" name="habit_code<?php //echo $i;?>" id="habit_code<?php //echo $i;?>" value="<?php //echo $id;?>" size="20" class="txt4" />--></td>
					<td width="78" align="center">
				  <input type="text" name="tw_no<?php echo $i;?>" id="tw_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="76" align="center">
				  <input type="text" name="ow_no<?php echo $i;?>" id="ow_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="68" align="center">
				  <input type="text" name="dcb_no<?php echo $i;?>" id="dcb_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
				  <td width="69" align="center">
				  <input type="text" name="dam_no<?php echo $i;?>" id="dam_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
				  <td width="72" align="center">
				  <input type="text" name="canal_no<?php echo $i;?>" id="canal_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
				  <td width="186" align="center">
				  <input type="text" name="other_no<?php echo $i;?>" id="other_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
				</tr>
				<?php  
				$i++;
				} ?>
			  </table>			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		
		<tr>
			<td bgcolor="#C5D8EB" height="28" colspan="9"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Number of Reservoirs in Supplied Villages (MH/OH)</font></span>            </td>
		</tr>
		<tr>
			<td>
				<table width="801" height="77" border="0" cellpadding="0" cellspacing="1" bgcolor="#FDF9EE" id="table4">
				<tr>
					<td colspan="14"><span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="184" align="center" rowspan="2" bgcolor="#F7E6B7">
						<font style="font-size: 8.5pt; font-style:normal" face="Verdana" color="#990000">
						Habitation</font></td>
				  <td align="center" width="72" rowspan="2" bgcolor="#F7E6B7">
					<address>
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
						Type MH/ OH</font></address>				  </td>
				  <td height="27" colspan="4" align="center" bgcolor="#F7E6B7">
					<address>
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Type of Reservoirs</font>
					</address>				  </td>
				</tr>
				<tr>
					<td width="91" height="18" align="center" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">GLR(Nos.)</font></td>
					<td align="center" width="81" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">GLSR(Nos.)</font></td>
					<td align="center" width="78" valign="top" bgcolor="#F7E6B7">
					<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">CWR(Nos.)</font></td>
					<td align="center" width="87" valign="top" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">OHSR(Nos.)</font></td>
				</tr>
				<?php
				$q5="SELECT DISTINCT  habit_name, habit_code, type_habit FROM tbl_dtls_ufw_habit WHERE status_a_na='Applicable' AND loc_id='$loc_id' order by habit_code";
				//echo $q5;
				$result5=mysql_query($q5);
				$i=1;
			    while(list($name, $id, $type)=mysql_fetch_array($result5))
				{
				//echo "name=" . $name;
				//echo "id=" . $id;
					?>
				<tr>
					<td width="184" height="22" align="center">
						<input type="text" name="habit_name<?php echo $i;?>" id="habit_name<?php echo $i;?>" value="<?php echo $name;?>" size="20" class="txt4" readonly />
				  <input type="hidden" name="habit_code<?php echo $i;?>" id="habit_code<?php echo $i;?>" value="<?php echo $id;?>" size="20" class="txt4" /></td>
				  <!--<td align="center" width="60"><input type="text" name="type_habit<?php //echo $i;?>" id="type_habit<?php //echo $i;?>" value="<?php //if($i==1){ echo "MH"; } else { echo "OH"; } ?>" size="2" class="txt_1" readonly/></td>-->
				  <td align="center" width="72"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php echo $type;?>" size="2" class="txt_1" readonly/></td>
					<td width="91" align="center">
				  <input type="text" name="glr_no<?php echo $i;?>" id="glr_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="81" align="center">
				  <input type="text" name="glsr_no<?php echo $i;?>" id="glsr_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="78" align="center">
				  <input type="text" name="cwr_no<?php echo $i;?>" id="cwr_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="87" align="center">
				  <input type="text" name="ohsr_no<?php echo $i;?>" id="ohsr_no<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
				</tr>
				<?php  $i++;
				} ?>
			  </table>			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td align="center">
				<input type="submit" value="Click for Continue" name="submit">			</td>
		</tr>
</table>
</form>
</div>		
</body>
</html>
